<layout name="layout" />
<div class="pageheader notab">
	<h1 class="pagetitle">
		<a href="/" class="linkWay">首页/思路优化</a>
		&nbsp;<span class="divider">»</span>&nbsp;
		<a class="currentWay">我的思路</a>
	</h1>
	<!--<ul class="breadcrumbs breadcrumbs2"  >
		<li><a href="/algorithm">我思故我牛</a><span class="divider">&#187;</span></li>
		<li>我的思路</li>
	</ul>-->
</div>
<style>
	.contentwrapper td a {
		margin-left: 5px;
	}
	.condition-input {
		width: 50px;
		display: inline-block;
	}
	#popup_container {
		top: 10% !important;
	}
	.s-model span{
		width: 100px;
		display: inline-block;
		margin-top: 5px;
	}
	.indexUnit {
		margin-left: 5px;
	}
	.k_box {
		margin-top:-20px;border-bottom:1px solid #DDDDDD;padding:10px 0px;
	}
	input {
		vertical-align: middle !important;
	}
	.siluResult-box{
		margin: 5px 5px 0px;
		max-height: 800px;
	}
	.filter_box {
		/*border: 1px solid #D8D8D8;*/
		padding: 4px;
		margin-bottom: 2px;
	}
</style>
<div clear="all"></div>
<div id="contentwrapper" class="contentwrapper">
	<div id="maincontent">
		<!-- <div style="padding-right:10px;width:60%; padding-bottom:10px;text-align:right;">
			<button class="stdbtn add-con">添加思路</button>
		</div> -->
		<div style="padding-right:20px;width:100%;float:left;">
			<div style="font-size: 20px;width: 100%;text-align: center;margin-bottom: 10px;">
				通用思路
			</div>
			<div>
				<table cellpadding="0" cellspacing="0" border="0" class="metrotable datatable">
					<thead id=>
					<tr>
						<th width="5%" class="head1">ID</th>
						<th width="13%" class="head0">思路</th>
						<th class="head1">内容</th>
						<th class="head0">来自</th>
						<th width="15%" class="head1">创建日期</th>
						<th width="15%" class="head0">操作</th>
					</tr>
					</thead>
					<tbody id="con-list-tr">
					<if condition="$list['public']['total_items'] == 0">
						<tr>
							<td colspan="6">暂无思路</td>
						</tr>
						<else/>
						<volist name="list['public']['items']" id="v">
							<tr <if condition="$v.status eq 2">class="red"</if>>
							<td>{$v.id}</td>
							<td>{$v.title}</td>
							<td>
								{$v.content}
							</td>
							<td width="100">
								通用思路
							</td>
							<td>{$v.add_time}</td>
							<td>
								<a href="javascript:;" class="think-edit" data-id="{$v.id}">编辑</a>
								<a href="javascript:;" class="think-delete" data-id="{$v.id}">删除</a>
								<br>
								<a href="javascript:;" class="think-execute" data-id="{$v.id}">执行思路</a>
								<if condition="$v.status eq 2">
									<br>
									<a href="/algorithm/status?id={$v.id}" class="red">解除异常</a>
								</if>
								<br>
								<a href="javascript:;" class="to-platform" data-title="{$v.title}" data-id="{$v.id}">转移到思路平台</a>
							</td>
							</tr>
						</volist>
					</if>
					</tbody>
				</table>
			</div>
		</div>
		<div style="width:100%;display:inline-block;">
			<div style="font-size: 20px;width: 100%;text-align: center;margin-bottom: 10px;">
				定制思路
			</div>
			<div>
				<table cellpadding="0" cellspacing="0" border="0" class="metrotable datatable">
					<thead id="">
					<tr>
						<th width="5%" class="head1">ID</th>
						<th width="13%" class="head0">思路</th>
						<th class="head1">内容</th>
						<th class="head0">来自</th>
						<th width="15%" class="head1">创建日期</th>
						<th width="15%" class="head0">操作</th>
					</tr>
					</thead>
					<tbody id="con-list-tr">
					<if condition="$list['custom']['total_items'] == 0">
						<tr>
							<td colspan="6">暂无思路</td>
						</tr>
						<else/>
						<volist name="list['custom']['items']" id="v">
							<tr <if condition="$v.status eq 2">class="red"</if>>
							<td>{$v.id}</td>
							<td>{$v.title}</td>
							<td>
								{$v.content}
							</td>
							<td width="100">
								定制思路
							</td>
							<td>{$v.add_time}</td>
							<td>
								<a href="javascript:;" class="think-edit" data-id="{$v.id}">编辑</a>
								<a href="javascript:;" class="think-delete" data-id="{$v.id}">删除</a>
								<br>
								<a href="javascript:;" class="think-execute" data-id="{$v.id}">执行思路</a>
								<if condition="$v.status eq 2">
									<br>
									<a href="/algorithm/status?id={$v.id}" class="red">解除异常</a>
								</if>
							</td>
							</tr>
						</volist>
					</if>
					</tbody>
				</table>
			</div>
		</div>
		<div style="width:100%;">
			<div style="font-size: 20px;width: 100%;text-align: center;margin-bottom: 10px;">
				我复制的策略（思路）
			</div>
			<div>
				<table cellpadding="0" cellspacing="0" border="0" class="metrotable datatable">
					<thead id="">
					<tr>
						<th width="5%" class="head1">ID</th>
						<th class="head0">来自</th>
						<th width="15%" class="head1">操作</th>
					</tr>
					</thead>
					<tbody id="con-list-tr">
					<if condition="$list['platform']['total_items'] == 0">
						<tr>
							<td colspan="3">暂无复制的策略</td>
						</tr>
						<else/>
						<volist name="list['platform']['items']" id="v">
							<tr>
								<td>{$v.id}</td>
								<td width="100" class="menuFullName">
									{$v.menu_full_name}
								</td>
								<td>
									<a href="javascript:;" data-id="{$v.id}" class="platSilu">详情</a>
								</td>
							</tr>
						</volist>
					</if>
					</tbody>
				</table>
			</div>
		</div>
	</div>
</div>
<script>
	$(document).ready(function(){
		if(!window.siluHelper){
			siluHelper = $.siluHelper();
		}

		$(document).on('click', '.think-delete', function(){
			var $this = $(this),
					id = $this.data('id');
			wt.showBox('确认删除思路?', '温馨提示', function(r) {
				if(r) {
					wt.ajax('/algorithm/delete', 'post', {id:id}, function(o) {
						var r = $.parseJSON(o);
						if(r.data.code == 'success') {
							$this.parents('tr').remove();
						}
						msg.close(index);
					})
				}
			});
		});

		// var siluHelper = new $.siluHelper("", {});
		$(document).on('click', '.think-execute', function(){
			siluHelper.execute({
				id: $(this).data('id'),
				campaign_id:'',
				adgroup_id: ''
			});
		});
		$(document).on('click', '.think-edit', function() {
			var p = {
				edit : true,
				silu_id : $(this).data('id')
			};
			siluHelper.setParams(p);
			siluHelper.init();
		});
		$(document).on('click', '.to-platform', function() {
			var option = {
				title : $(this).data('title'),
				siluId : $(this).data('id'),
			}
			var html = template.render('silu-to-platform', option);
			msg.open({
				type: 1,
				//skin: 'layui-layer-lan',
				title: '转移到思路平台 ————' + option.title,
				fix: false,
				shadeClose: true,
				area: ['400px', '200px'],
				content:html,
			});

			getTree();
		});


		$(document).on('click', '.subToPlatform', function() {
			var id = $('#siluId').val();
			var platform = $('#platform').val();
			if(platform == '' || id == '') {
				alert('请选择正确的分类');
			} else {
				wt.post('/algorithm/toPlatformSilu', {
					platform : $('#platform').val(),
					siluId : id
				}, function(r) {
					var o = $.parseJSON(r);
					if(o.data.status == 1) {
						window.location.href="/algorithm/platform?pid="+platform;
					} else {
						wt.showBox(o.data.msg, '温馨提示');
					}
				});
			}
		});

		$(document).on('click', '.platSilu', function() {
			var $this = $(this),
					id = $this.data('id'),
					option = {
						menu_full_name : $this.parents('tr').find(".menuFullName").text()
					};
			wt.post('/algorithm/getMyCopyById', {id : id}, function(res) {
				var o = $.parseJSON(res);
				if(o.data.status == 1)
					wt.showBox(o.data.msg, '温馨提示');
				else
					msg.open({
						type: 1,
						//skin: 'layui-layer-lan',
						title: option.menu_full_name,
						fix: false,
						shadeClose: true,
						area: ['700px', 'auto'],
						content:template.render('myCpoySilu', o.data)
					});
			});
		});
		$(document).on('change', '.change-platform', function() {
			var id = $(this).val(),
					sync = $(".toPlatform").data('rel');
			sync = sync ? true : false;
			$(this).parent('.v1').nextAll('.v1').remove();
			if(!sync)
				$('#platform').val('');
			if(id) {
				getTree(id, sync);
			} else if (sync){
				// $('#platform').val($(this).data('parent-path'));
				getTree($(this).data('parent-path'), sync, true);
			}
		});
	});
</script>

<script id="silu-to-platform" type="text/html">
	<style>
		.toPlatform .v1{
			margin: 10px 0px 0px 10px;
			float: left;
		}
		.btnBOx {
			margin: 10px;
		}
	</style>
	<div class="toPlatform"></div>
	<br clear="all">
	<div class="btnBOx">
		<form>
			<input type="hidden" id="platform" name="platform" value="">
			<input type="hidden" id="siluId" name="siluId" value="<%= siluId%>">
			<button type="button" class="subToPlatform">确定</button>
		</form>
	</div>
</script>
<script id="myCpoySilu" type="text/html">
	<div style="padding: 10px 10px;max-height:400px;overflow:auto;">
		<table cellpadding="0" cellspacing="0" border="0" class="metrotable datatable">
			<thead id="">
			<tr>
				<th width="5%" class="head1">ID</th>
				<th width="13%" class="head0">思路</th>
				<th class="head1">内容</th>
				<th width="15%" class="head0">创建日期</th>
				<th width="15%" class="head1">操作</th>
			</tr>
			</thead>
			<tbody id="con-list-tr">
			<% if(total_items == 0) { %>
			<tr>
				<td colspan="6">暂无思路</td>
			</tr>
			<% } else { %>
			<% for (i = 0; i < total_items; i ++) { %>
			<tr>
				<td><%= items[i].id %></td>
				<td><%= items[i].title %></td>
				<td>
					<%== items[i].content %>
				</td>
				<td><%= items[i].add_time %></td>
				<td>
					<a href="javascript:;" class="think-edit" data-id="<%= items[i].id %>">编辑</a>&nbsp;
					<a href="javascript:;" class="think-delete" data-id="<%= items[i].id %>">删除</a>
					<br>
					<a href="javascript:;" class="think-execute" data-id="<%= items[i].id %>">执行思路</a>
				</td>
			</tr>
			<% } %>
			<% } %>
			</tbody>
		</table>
	</div>
</script>
